#ifndef __UDP_H__
#define __UDP_H__

#include "protocal_define.h"
#include "radar.h"
#include "respond_struct_define.h"
#include <errno.h>
#include <iostream>
#include <list>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/epoll.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>

/*
各个功能的端口号
*/
#define HEARTBEART_PORT 6002
#define PLAYLOAD_PORT 6002
#define DRONE_PORT 6002
#define MFREQUENCY_PORT 6002
#define DATALOAD_PORT 6002
#define SIGALTABLE_PORT 6002
#define TARGET_PORT 6002
#define POSITION_PORT 6002
using namespace std;
/*
通信过程中一些参数设置
*/
#define MAX_EVENTS 10
#define MAX_BUFFER_SIZE 1024

class Udp {

  public:
    Udp(int port, const char *serverip, std::function<void(uint8_t *, int)>);
    ~Udp();

  public:
    int StartCommunication(void);
    int SendMsg(const uint8_t *buffer, int len);

  private:
    int clientport; // 客户端端口号
    struct sockaddr_in m_sender_addr;
    int sockfd;       // socket file descriptor
    char localIP[20]; // 本机IP地址
    std::function<void(uint8_t *, int)> _on_recv;
};

#endif // #ifndef __UDP_H__
